package com.ruoyi.business.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.TbGoodsOrder;
import com.ruoyi.business.service.ITbGoodsOrderService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售订单管理Controller
 * 
 * @author ruoyi
 * @date 2021-04-24
 */
@Controller
@RequestMapping("/business/order")
public class TbGoodsOrderController extends BaseController
{
    private String prefix = "business/order";

    @Autowired
    private ITbGoodsOrderService tbGoodsOrderService;

    @RequiresPermissions("business:order:view")
    @GetMapping()
    public String order()
    {
        return prefix + "/order";
    }

    /**
     * 查询销售订单管理列表
     */
    @RequiresPermissions("business:order:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbGoodsOrder tbGoodsOrder)
    {
        startPage();
        List<TbGoodsOrder> list = tbGoodsOrderService.selectTbGoodsOrderList(tbGoodsOrder);
        return getDataTable(list);
    }

    /**
     * 导出销售订单管理列表
     */
    @RequiresPermissions("business:order:export")
    @Log(title = "销售订单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbGoodsOrder tbGoodsOrder)
    {
        List<TbGoodsOrder> list = tbGoodsOrderService.selectTbGoodsOrderList(tbGoodsOrder);
        ExcelUtil<TbGoodsOrder> util = new ExcelUtil<TbGoodsOrder>(TbGoodsOrder.class);
        return util.exportExcel(list, "销售订单管理数据");
    }

    /**
     * 新增销售订单管理
     */
    @GetMapping("/add")
    public String add(Long goodsId, ModelMap mmap)
    {
        TbGoodsOrder tbGoodsOrder = tbGoodsOrderService.selectTbGoodsOrderByGoodsId(goodsId);

        mmap.put("tbGoodsOrder", tbGoodsOrder);
        return prefix + "/add";
    }

    /**
     * 新增销售订单管理
     */
    @GetMapping("/addadd")
    public String addadd(ModelMap mmap)
    {
        return prefix + "/addadd";
    }

    /**
     * 新增保存销售订单管理
     */
    @RequiresPermissions("business:order:add")
    @Log(title = "销售订单管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbGoodsOrder tbGoodsOrder)
    {
        return toAjax(tbGoodsOrderService.insertTbGoodsOrder(tbGoodsOrder));
    }

    /**
     * 修改销售订单管理
     */
    @GetMapping("/edit/{ID}")
    public String edit(@PathVariable("ID") Long ID, ModelMap mmap)
    {
        TbGoodsOrder tbGoodsOrder = tbGoodsOrderService.selectTbGoodsOrderById(ID);
        mmap.put("tbGoodsOrder", tbGoodsOrder);
        return prefix + "/edit";
    }

    /**
     * 修改保存销售订单管理
     */
    @RequiresPermissions("business:order:edit")
    @Log(title = "销售订单管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbGoodsOrder tbGoodsOrder)
    {
        return toAjax(tbGoodsOrderService.updateTbGoodsOrder(tbGoodsOrder));
    }

    /**
     * 删除销售订单管理
     */
    @RequiresPermissions("business:order:remove")
    @Log(title = "销售订单管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbGoodsOrderService.deleteTbGoodsOrderByIds(ids));
    }
}
